package com.example.sport.config;

import com.example.sport.interceptors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] swaggerExcludes = new String[]{
                "/user/login",
                "/user/register",
                "/user/simpleLogin",
                "/file/**",
                "/captcha/**",

                "/doc.html",//文档主页
                "/favicon.ico",

                "/swagger-ui/index.html",
                "/swagger-ui.html",
                "/swagger-resources/**",
                "/swagger-ui/**",
                "/v3/**",
                "/webjars/**"};
        //登录和注册接口不拦截
        registry.addInterceptor(loginInterceptor).excludePathPatterns(swaggerExcludes);

    }

    /**
     * 解决resources下面静态资源无法访问
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/favicon.ico")//favicon.ico
                .addResourceLocations("classpath:/static/");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }


}
